import network,sys,os

if __name__ == '__main__':
    start=int(sys.argv[1])
    end=int(sys.argv[2])
    try:
        path=sys.argv[3]
    except:
        path="./tmp"

    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            print('wrong path')
            sys.exit("Exiting")

    while(start<end):
        filename=path+"/"+str(start)+".jpg"
        imageUrl="http://images.phapit.com/uploaded_pics/phap"+str(start)+".jpg"
        if not os.path.exists(filename):
            print(imageUrl,filename)
            imageUrl=network.httpLink(imageUrl)
            if imageUrl:
                f=open(filename,'wb')
                f.write(imageUrl.read())
                f.close()
        else:
            print("exists")
        start+=1



